package swing.swing03;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class MessageDialogTest {
    JFrame fr=new JFrame("测试消息对话框");

    JTextArea ta=new JTextArea(6,30);

    JButton btn=new JButton(new AbstractAction("弹出消息对话框"){
        @Override
        public void actionPerformed(ActionEvent e){
          String text=ta.getText();
          //JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.ERROR_MESSAGE);
          //JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.INFORMATION_MESSAGE);
          //JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.WARNING_MESSAGE);
           //JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.QUESTION_MESSAGE);
           //JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.PLAIN_MESSAGE);
           //自定义图标
           JOptionPane.showMessageDialog(fr,text,"消息对话框",JOptionPane.WARNING_MESSAGE,new ImageIcon("md_00\\img\\sex\\female.png"));

        }
    });

    public void init(){
        //组装视图
        fr.add(ta);
        fr.add(btn, BorderLayout.SOUTH);
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.pack();
        fr.setVisible(true);
    }

    public static void main(String[] args){
        new MessageDialogTest().init();
    }

}
